<link rel="stylesheet" href="../public/js/vendor/laydate/need/laydate.css">
<link rel="stylesheet" href="../public/js/vendor/laydate/skins/default/laydate.css">
<script src="../public/js/vendor/laydate/laydate.js"></script>
<div class="content_wrapper">

    <div class="container-fluid">
        <div class="row">
            <div class="col-sm-12">
                <aside>
                    <header><i class="fa fa-fw fa-file"></i>非冰鲜供应列表</header>
                    <section>
                        <div class="container-fluid">
                            <div class="row">
                                <div class="col-sm-12">
                                    <div class="btn-group" style="margin-bottom:20px;">
                                        <button class="btn btn-default" id="check_pass">审核通过</button>
                                        <button class="btn btn-default" id="check_faile">审核失败</button>
                                        <button class="btn btn-default J_ajax_content_modal" data-href="./isupply/search.html">查找</button>
                                    </div>

                                    <div class="table-responsive">
                                        <table id="isupply_table" class="table table-striped table-bordered table-hover" cellspacing="0" width="100%">
                                            <thead>
                                            <tr>
                                                <th><input class="all_item_check" type="checkbox" value="" /></th>
                                                <th>id</th>
                                                <th>标题</th>
                                                <th>电话</th>
                                                <th>品类</th>
                                                <th>发布量</th>
                                                <th>价格</th>
                                                <th>存储方式</th>
                                                <th>发布时间</th>
                                                <th>状态</th>
                                            </tr>
                                            </thead>
                                            <tbody>

                                            </tbody>
                                        </table>
                                    </div>
                                    <nav id="pagination-hsx">

                                    </nav>
                                </div>
                            </div>
                        </div>
                    </section>
                </aside>
            </div>
        </div>
    </div>


</div>

<script>
    $(document).ready(function () {
        var page;
        var lists;
        getISupplyData(1,undefined);
        $("#check_pass").click(function () {
            updateStatus(1);
        });
        $("#check_faile").click(function () {
            updateStatus(-1);
        });
    });

    function updateStatus(state) {
        var chk_value =[];
        var processFlag=true;
        $('input[name="idsindex"]:checked').each(function(){
            var tempObj=lists[$(this).val()];
            if(tempObj.state==state){
                alert("第"+($(this).val()+1)+"行与操作状态一致");
                processFlag=false;
                return false;
            }else{
                chk_value.push(tempObj.id);
            }

        });

        if(chk_value.length==0) return;

        if(processFlag){
            //更新状态
            $.ajax({
                type: 'post',
                url: common_conf.requestUrl+'isupply/updateState',
                contentType : 'application/json;charset=UTF-8',
                cache: false,
                data: '{"ids":'+chk_value.toString()+','+'"state":'+state+'}',
                dataType: 'json',
                beforeSend: function () {
                },
                success: function (returnData) {
                    if(forceLogin(returnData)) return;
                    var obj=returnData;
                    if(obj.state=="success"){
                        alert(obj.message);
                        getISupplyData(page.pageIndex,undefined);
                    }else{
                        alert(obj.message);
                    }
                },
                error: function () {
                    alert("未找到模板");
                }
            });


        }

    }

    function getISupplyData(pageIndex,paramjson) {

        if(undefined==paramjson){
            var paramjson=new Object();
        }
        paramjson.pageIndex=pageIndex;
        paramjson=JSON.stringify(paramjson);

        $.ajax({
            type: 'post',
            url: common_conf.requestUrl+'isupply/list',
            contentType : 'application/json;charset=UTF-8',
            cache: false,
            data: paramjson,
            dataType: 'json',
            beforeSend: function () {
            },
            success: function (returnData) {
                var obj=returnData;
                if(obj.state=="success"){
                    var values=Array();
                    $.each(obj.list,function(index,isupply){
                        val=Array();
                        var statutext="";
                        switch (isupply.state){
                            case -1:
                                statutext="审核失败";
                                break;
                            case 0:
                                statutext="审核中";
                                break;
                            case 1:
                                statutext="审核通过";
                                break;
                        }
                        var fishInfo=JSON.parse(isupply.fishInfo);
                        val[0]=isupply.id;
                        val[1]=isupply.title;
                        val[2]=isupply.user_phone;
                        val[3]=fishInfo.fishName+"("+fishInfo.specName+")";
                        val[4]=isupply.quantity;
                        val[5]=isupply.priceInfo;
                        var storage_text="";
                        switch (isupply.storage){
                            case 1:
                                storage_text="冻品";
                                break;
                            case 2:
                                storage_text="远洋";
                                break;
                            case 3:
                                storage_text="已加工";
                                break;
                            case 4:
                                storage_text="养殖";
                                break;
                        }
                        val[6]=storage_text;
                        val[7]=isupply.displayTime;
                        val[8]=statutext;
                        values.push(val);
                    });
                    initTable("#isupply_table",values,"./#isupply/edit.html");
                    page=obj.page;
                    lists=obj.list;
                    paginate(page,"pagination-hsx");
                    clickBind(page,"getISupplyData",paramjson);
                    $modals=$('.modal');
                    $modals.modal('hide');
                }else{
                    alert(obj.message);
                }
            },
            error: function () {
                alert("未找到模板");
            }
        });
    }

</script>